import { BaseResultType } from '#/request'
import useDealResult from '@/hooks/dealResult'
import uniRequest from '@/request'

const { dealResult, checkResult,dealResultNOMSG } = useDealResult()

export const getDeviceCabinetInfo = async (id: string): Promise<BaseResultType<any> | null> => {
  const [result, err] = await uniRequest.get('/kdg/api/getDeviceCabinetInfo?deviceId=' + id)
  return Promise.resolve(dealResult(err, result))
}

export const reservationOrder = async (deviceId: string, phon: string, pwdstr: string, wxId: string): Promise<BaseResultType<any> | null> => {
  const [result, err] = await uniRequest.get('/kdg/api/reservationOrder?deviceId=' + deviceId + '&phon=' + phon + '&pwdstr=' + pwdstr + '&wxId=' + wxId)
  return Promise.resolve(dealResult(err, result))
}
export const getUserStorageById = async (userStorageId: string): Promise<BaseResultType<any> | null> => {
  const [result, err] = await uniRequest.get('/kdg/api/getUserStorageById?id=' + userStorageId)
  return Promise.resolve(dealResult(err, result))
}
export const reinitializeOrder = async (userStorageId: string): Promise<BaseResultType<any> | null> => {
  const [result, err] = await uniRequest.get('/kdg/api/reinitializeOrder?userStorageId=' + userStorageId)
  return Promise.resolve(dealResult(err, result))
}
export const reinitializeOrderNew = async (userStorageId: string, deviceCabinetId: string): Promise<BaseResultType<any> | null> => {
  const [result, err] = await uniRequest.get(`/kdg/api/reinitializeOrderNew?userStorageId=${userStorageId}&deviceCabinetId=${deviceCabinetId}`)
  return Promise.resolve(dealResult(err, result))
}
export const getDeviceCabinet = async (deviceId: string): Promise<BaseResultType<any> | null> => {
  const [result, err] = await uniRequest.get('/kdg/api/getDeviceCabinet?deviceId=' + deviceId)
  return Promise.resolve(dealResult(err, result))
}

export const confirmOrder = async (userStorageId: string): Promise<BaseResultType<any> | null> => {
  const [result, err] = await uniRequest.get('/kdg/api/confirmOrder?userStorageId=' + userStorageId)
  return Promise.resolve(dealResultNOMSG(err, result))
}
export const getUserStorageInfo = async (userStorageId: string): Promise<BaseResultType<any> | null> => {
  const [result, err] = await uniRequest.get('/kdg/api/getUserStorageInfo?userStorageId=' + userStorageId)
  return Promise.resolve(dealResult(err, result))
}

export const withdrawal = async (userId: string, sum: string): Promise<BaseResultType<any> | null> => {
  const [result, err] = await uniRequest.get('/kdg/api/withdrawal?userId=' + userId + '&sum=' + sum)
  return Promise.resolve(dealResult(err, result))
}
